package top.hkyzf.study.leetcode.array;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-3-4 9:23
 */
public class 子数组范围和_2104 {
    public long subArrayRanges(int[] nums) {
        long result = 0;
        if (nums.length == 1) {
            return 0;
        }
        for (int i = 0; i < nums.length-1; i++) {
            int min = nums[i], max = nums[i];
            for (int j = i+1; j < nums.length; j++) {
                min = Math.min(min, nums[j]);
                max = Math.max(max, nums[j]);
                result += max - min;
            }
        }
        return result;
    }

    @Test
    public void testSubArrayRanges () {
        int[] nums = {4,-2,-3,4,1};
        System.out.println(subArrayRanges(nums));
    }
}
